package website.lucaswork.survey.core.converters;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import website.lucaswork.survey.core.utils.DefaultValues;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@Component
public class DateToStringConverter implements Converter<LocalDate, String> {

    @Autowired
    DefaultValues defaultValues;

    @Override
    public String convert(LocalDate source) {
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern(defaultValues.getDefaultDateFormat());
        return source.format(dtf);
    }
}
